| Conditions | 3 |
| Paths | 9 |
| Total Lines | 55 |
| Lines | 55 |
| Ratio | 100 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | View Code Duplication | import { |
|
| 9 | var route = function(req, res, next){ |
||
| 10 | Hooks.instance.trigger('beforeRoute', req, res, next) |
||
| 11 | if(typeof res._header !== 'undefined' && res._header !== null) return |
||
| 12 | |||
| 13 | var filePath = cleanSlug(req.body.filePath) |
||
| 14 | var p = new Promise((resolve) => { |
||
| 15 | cmsOperations.save.save( |
||
| 16 | fileUtils.getFilePath(filePath), |
||
| 17 | req.body.tplPath, |
||
| 18 | req.body.json, |
||
| 19 | '', |
||
| 20 | 'draft', |
||
| 21 | null, |
||
| 22 | 'publish') |
||
| 23 | .then(() => { |
||
| 24 | resolve() |
||
| 25 | }).catch(function(e) { |
||
| 26 | console.error(e) |
||
| 27 | }) |
||
| 28 | }) |
||
| 29 | |||
| 30 | p.then((resSave) => { |
||
| 31 | cmsOperations.save.save( |
||
| 32 | fileUtils.getFilePath(req.body.filePath), |
||
| 33 | req.body.tplPath, |
||
| 34 | req.body.json, |
||
| 35 | '', |
||
| 36 | 'publish', |
||
| 37 | resSave, |
||
| 38 | 'publish') |
||
| 39 | .then((resSave) => { |
||
| 40 | if(typeof resSave.error !== 'undefined' && resSave.error !== null ){ |
||
| 41 | res.set('Content-Type', 'application/json') |
||
| 42 | res.send(JSON.stringify({error: resSave.error})) |
||
| 43 | } |
||
| 44 | var result |
||
| 45 | if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){ |
||
| 46 | result = resSave |
||
| 47 | } |
||
| 48 | if(typeof resSave.json !== 'undefined' && resSave.json !== null){ |
||
| 49 | result = { |
||
| 50 | success: 1, |
||
| 51 | json: resSave.json |
||
| 52 | } |
||
| 53 | } |
||
| 54 | Manager.instance.updateList() |
||
| 55 | res.set('Content-Type', 'application/json') |
||
| 56 | res.send(JSON.stringify(result)) |
||
| 57 | }).catch(function(e) { |
||
| 58 | console.error('post-publish.js', e) |
||
| 59 | }) |
||
| 60 | }).catch(function(e) { |
||
| 61 | console.error('post-publish.js', e) |
||
| 62 | }) |
||
| 63 | } |
||
| 64 | |||
| 65 | export default route |